package one;

import org.junit.Test;
import static org.junit.Assert.*;

public class ExpressionUnitTest {

    // 测试加法
    @Test
    public void testAdd() {
        Expression expr = new Expression(3, 5, '+');
        assertEquals(8, expr.getResult());
    }

    // 测试减法（结果非负）
    @Test
    public void testSubtract() {
        Expression expr1 = new Expression(5, 3, '-');
        Expression expr2 = new Expression(3, 5, '-');
        assertEquals(2, expr1.getResult());
        assertEquals(2, expr2.getResult()); // 交换后结果一致
    }

    // 测试乘法
    @Test
    public void testMultiply() {
        Expression expr = new Expression(4, 6, '*');
        assertEquals(24, expr.getResult());
    }

    // 测试除法（整除）
    @Test
    public void testDivide() {
        Expression expr1 = new Expression(12, 4, '/');
        Expression expr2 = new Expression(4, 12, '/'); // 交换后仍整除
        assertEquals(3, expr1.getResult());
        assertEquals(3, expr2.getResult());
    }

    // 测试非法运算符
    @Test(expected = IllegalArgumentException.class)
    public void testInvalidOperator() {
        new Expression(1, 2, '%');
    }

    // 测试除数为0
    @Test(expected = IllegalArgumentException.class)
    public void testDivideByZero() {
        new Expression(1, 0, '/');
    }
}
